//
//  MKCollectionModelObjectBase.m
//  MKUI
//
//  Created by 苏尚进 on 2020/10/10.
//  Copyright © 2020 moon. All rights reserved.
//

#import "MKCollectionModelObjectBase.h"
@interface MKCollectionModelObjectBase(){
    NSMutableDictionary *_dynamicProperties;
}
@end
@implementation MKCollectionModelObjectBase
- (id)init{
    if (self=[super init]) {
        _dynamicProperties = [[NSMutableDictionary alloc] init];
    }
    return self;
}
- (id)copyWithZone:(NSZone *)zone{
    MKCollectionModelObjectBase *obj = [self.class allocWithZone:zone];
    obj->_dynamicProperties = [_dynamicProperties mutableCopy];
    obj.modelValue = self.modelValue;
    return obj;
}
+ (MKCollectionModelObjectBase *)modelWithValue:(nullable id)modelVaule{
    MKCollectionModelObjectBase *m = [[self alloc] init];
    m.modelValue = modelVaule;
    return m;
}
- (NSMutableDictionary *)dynamicProperties{
    return _dynamicProperties;
}
- (void)setObject:(nullable id)obj forKeyedSubscript:(id<NSCopying>)key{
    if(obj==nil){
        [_dynamicProperties removeObjectForKey:key];
    }else{
        _dynamicProperties[key] = obj;
    }
}
- (nullable id)objectForKeyedSubscript:(id<NSCopying>)key{
    id value = _dynamicProperties[key];
    return value;
}
@end
#import "NSObject+MKUI.h"
@implementation MKCollectionModelObjectBase(MKUI_ValueForKeyPathOtherwise)
- (nullable id)mk_valueForKeyPath:(NSString *)path otherwise:(nullable id)other{
    return [_dynamicProperties mk_valueForKeyPath:path otherwise:other];
}
@end
